//
//  TextResultDisplayViewController.swift
//  月升
//
//  Created by qinjiangtao on 2024/1/29.
//  文字结果展示页面

import UIKit
import GKPhotoBrowser

class TextResultDisplayViewController: QIBaseViewController {

    var typeStr = ""
    var model = MedicalReportsyModel()
    private var imgView = UIImageView()
    private var explainL = YYLabel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = typeStr

        addUI()
        getData()
    }
    
    private func getData() {
        if typeStr == "居家检测" {
            QINetworkManager.requestJson(urlStr: "/Project/roomDetail", method: .get, parameters: ["id": model.id]) { json in
                print(json)
            }
        } else if typeStr == "医疗报告" {
            QINetworkManager.requestJson(urlStr: "/Project/medical", method: .get, parameters: ["id": model.id]) { json in
                print(json)
            }
        }
        
    }


    private func addUI() {
        self.view.addGradientColor(fromColors: [ColorWithStr("#FFB2B5").cgColor, ColorWithStr("#FCDFE0").cgColor, ColorWithStr("#FFFBFB").cgColor], locationArr: [0, 0.5, 1.0], with: .topToBottom)
        
        imgView = UIImageView().then {
            $0.frame = CGRect(x: 20, y: NAV_HEIGHT, width: SCREEN_WIDTH - 40, height: 200)
            $0.image = UIImage(named: "noo")
            $0.contentMode = .scaleAspectFill
            $0.clipsToBounds = true
            $0.isUserInteractionEnabled = true
            $0.addRoundedCorners(withRadius: 8)
        }
        view.addSubview(imgView)
        imgView.kf.setImage(with: URL(string: "\(IMAGE_URL)\(model.image)"))
        let tap = UITapGestureRecognizer(target: self, action: #selector(imgBtnClick))
        imgView.addGestureRecognizer(tap)
        
        let titleL = UILabel().then({
            $0.frame = CGRect(x: 20, y: imgView.bottom + 25, width: 100, height: 22)
            $0.text = "结果"
            $0.textColor = Color333333
            $0.font = SYSFONTBOLD(ofSize: 16)
        })
        view.addSubview(titleL)
        
        explainL = YYLabel().then({
            $0.frame = CGRect(x: 20, y: titleL.bottom + 5, width: SCREEN_WIDTH - 40, height: 300)
            $0.backgroundColor = .clear
            $0.textContainerInset = UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
            $0.numberOfLines = 0
            $0.textVerticalAlignment = .top
            $0.text = model.predict
            $0.textColor = Color333333
            $0.font = SYSFONT(ofSize: 15)
            $0.addRoundedCorners(withRadius: 10)
        })
        view.addSubview(explainL)
        
    }
    
    @objc private func imgBtnClick() {
        var photos = [GKPhoto]()
        let photo = GKPhoto()
        photo.image = imgView.image
        photos.append(photo)
        
        
        let browser = GKPhotoBrowser(photos: photos, currentIndex: 0)
        browser.showStyle = .none
        browser.show(fromVC: self)
        
    }

}
